package com.spark.tags;

import java.util.Map;

import com.spark.core.SparkContext;
import com.spark.core.XMap;

public class ImageCode extends ViewComponent {
	
	private static final String DEFAULT_TEMPLATES = "imageCode.ftl";
	
	public String getTemplate() {
		return DEFAULT_TEMPLATES;
	}
	
	public void init(XMap view, SparkContext context) throws Exception {
		super.init(view, context);
	}
	
	@SuppressWarnings("unchecked")
	protected String build(SparkContext context){
		Map map = context.getMap();
		StringBuilder sb = new StringBuilder();
		sb.append("<img src=\"imagecode\" title=\"看不清?点击切换图片.\" style=\"border:1px solid #bababa;cursor:pointer;").append(get(map,"style")).append("\" width=\"78\" height=\"18\"  id=\"").append(get(map,"id")).append("\"></img>\r");
		sb.append("<script>new Spark.ImageCode(").append(get(map,"config")).append(");</script>\r");
		return sb.toString();
	}
}
